package testtiles.state;

import testtiles.object.Unit;
import butines.game.Sprite.Animation;


public class UnitStayState extends AbstractState<Unit> {

	private static final UnitStayState instance = new UnitStayState();

	public static UnitStayState getInstance() {
		return instance;
	}

	@Override
	public void enter(Unit owner) {
		owner.setSpeed(0);
		owner.getSteering().getSeparation().on();
		owner.getSteering().getCohesion().on();
	}
	
	@Override
	public void leave(Unit owner) {
		owner.getSteering().getSeparation().off();
		owner.getSteering().getCohesion().off();
	}

	@Override
	public void execute(Unit owner) {
		
		if (owner.getSpeed() > 0.05) {
			Animation walk = owner.getAnimations().getWalk();
			if (walk.isPlaying() == false) {
				walk.play();
			}
			return;
		}

		Animation stay = owner.getAnimations().getStay();
		if (stay.isPlaying() == false) {
			stay.play();
		}
		
	}


}
